#pragma once

#include <iostream>
#include <string>
#include <vector>
#include<unistd.h>
#include<fcntl.h>

using namespace std;

class Util
{
public:
    // 设文件描述为非阻塞状态的函数
    static bool SetNonBlock(int fd)
    {
        if(fd<0)
        {
            std::cout<<"fd<0"<<std::endl;
            return false;
        }
        int fl=fcntl(fd,F_GETFL);
        if(fl<0)
        {
            return false;
        }
        fcntl(fd,F_SETFL,fl|O_NONBLOCK);
        return true;
    }

    static bool StringSplit(const string &str, const string &sep, vector<string> *v)
    {
        size_t start = 0;
        while (start < str.size())
        {
            auto pos = str.find(sep, start);
            if (pos == std::string::npos)
                break;
            std::string tmp = str.substr(start, pos - start);
            v->push_back(tmp);
            start = pos + sep.size();
        }
        if (start < str.size())
        {
            std::string tmp = str.substr(start);
            v->push_back(tmp);
        }
        return true;
    }
};